<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.ico">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-material.min.css">
  <script src="/lib/pace/pace.min.js"></script>


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('https://ychienhung.gitee.io').hostname,
    root: '/',
    scheme: 'Muse',
    version: '7.6.0',
    exturl: false,
    sidebar: {"position":"right","display":"post","padding":18,"offset":12,"onmobile":false},
    copycode: {"enable":true,"show_result":true,"style":"mac"},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
  };
</script>

  <meta name="description" content="特地写下这篇文章，以便以后复习使用。">
<meta property="og:type" content="article">
<meta property="og:title" content="单片机培训日志">
<meta property="og:url" content="https://ychienhung.gitee.io/2019/12/27/%E5%8D%95%E7%89%87%E6%9C%BA%E5%9F%B9%E8%AE%AD%E6%97%A5%E5%BF%97/index.html">
<meta property="og:site_name" content="YChienHung&#39;s blog">
<meta property="og:description" content="特地写下这篇文章，以便以后复习使用。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-12-27T08:51:44.000Z">
<meta property="article:modified_time" content="2020-01-17T10:45:32.831Z">
<meta property="article:author" content="YChienHung">
<meta property="article:tag" content="单片机">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://ychienhung.gitee.io/2019/12/27/%E5%8D%95%E7%89%87%E6%9C%BA%E5%9F%B9%E8%AE%AD%E6%97%A5%E5%BF%97/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>
  <title>单片机培训日志 | YChienHung's blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="YChienHung's blog" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">YChienHung's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-memoir">

    <a href="/memoir/" rel="section"><i class="fa fa-fw fa-sitemap"></i>回忆录</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="none"
           placeholder="搜索..." spellcheck="false"
           type="text" id="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://ychienhung.gitee.io/2019/12/27/%E5%8D%95%E7%89%87%E6%9C%BA%E5%9F%B9%E8%AE%AD%E6%97%A5%E5%BF%97/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="YChienHung">
      <meta itemprop="description" content="Forget me not.">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="YChienHung's blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          单片机培训日志
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-12-27 16:51:44" itemprop="dateCreated datePublished" datetime="2019-12-27T16:51:44+08:00">2019-12-27</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-01-17 18:45:32" itemprop="dateModified" datetime="2020-01-17T18:45:32+08:00">2020-01-17</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>5.4k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>5 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>特地写下这篇文章，以便以后复习使用。<a id="more"></a></p>
<h2 id="开发板介绍"><a href="#开发板介绍" class="headerlink" title="开发板介绍"></a>开发板介绍</h2><p>国信长天单片机竞赛实训平台</p>
<ol>
<li><p>MCU： IAP15F2K61S2 </p>
</li>
<li><p>复位按键(S1</p>
<p>​    按下可复位竞赛平台  注：要在stc-isp中取消选择 复位脚作为IO</p>
</li>
<li><p>按键模式选择跳线（J5）</p>
<ul>
<li><p>KBD：矩阵按键模式  控制  S4~ S19 为矩阵按键模式</p>
</li>
<li><p>BTN：独立按键模式  控制  S4 ~  S7 为独立按键模式</p>
</li>
</ul>
</li>
<li><p>下载模块</p>
<p>​    U3及其外围器件，是平台的下载功能模块。</p>
<p>​    L9是电源指示灯，接通电源常亮</p>
<p>​    L11 、L12是串口灯，下载或串口时闪烁</p>
</li>
<li><p>编程方式选择跳线（J13）</p>
<ul>
<li><p>IO编程方式</p>
</li>
<li><p>MM编程方式，即存储器映射扩展模式，其英文全称为：Memory Mapped Extended Modd</p>
</li>
</ul>
</li>
<li><p>对比度调节电位器 </p>
<p>​    Rb1是竞赛平台的LCD1602、LCD12864液晶显示器的对比度调节电位器</p>
</li>
<li><p>LCD1602   接口  (Rb1右方短的那个接口)</p>
</li>
<li><p>LCD12864 接口  (Rb1右方长的那个接口)</p>
</li>
<li><p>超声波测距模块（JS1, JS2）</p>
</li>
<li><p>超声红外选择跳线（J2）</p>
<ul>
<li><p>4-2 3-1：超声波测距模块</p>
</li>
<li><p>4-6 3-5：红外收发模块</p>
</li>
</ul>
</li>
<li><p>8*8点阵模块接口（U22、U23）</p>
</li>
<li><p>红外收发模块（LD1、U20）</p>
</li>
<li><p>霍尔元件接口（U21）</p>
</li>
<li><p>74HC138编码器（U24）</p>
</li>
<li><p>温度传感器（U5）</p>
<p>​    DS18B20的温度传感器，可测量当前环境温度</p>
</li>
<li><p>数码管（DS1、DS2）及锁存器（U7、U8）</p>
</li>
<li><p>138 译码器（U9）</p>
<p>   注：Yx  x的二进制就是P27 P26 P25 (高三位)</p>
<table>
<thead>
<tr>
<th>代号</th>
<th>功能</th>
</tr>
</thead>
<tbody><tr>
<td>74HC138 - Y0</td>
<td>未用</td>
</tr>
<tr>
<td>74HC138 - Y1</td>
<td>未用</td>
</tr>
<tr>
<td>74HC138 - Y2</td>
<td>未用</td>
</tr>
<tr>
<td>74HC138 - Y3</td>
<td>未用</td>
</tr>
<tr>
<td>74HC138 - Y4    0x80</td>
<td>8*LED 锁存</td>
</tr>
<tr>
<td>74HC138 - Y5    0xA0</td>
<td>ULN2003 锁存</td>
</tr>
<tr>
<td>74HC138 - Y6    0xC0</td>
<td>数码管位选锁存</td>
</tr>
<tr>
<td>74HC138 - Y7    0xE0</td>
<td>数码管段选锁存</td>
</tr>
</tbody></table>
</li>
</ol>
<ol start="18">
<li><p>驱动模块（U10）</p>
<p>​    ULN2003驱动模块</p>
</li>
<li><p>8*LED（L1~L8）及其锁存器（U6）</p>
</li>
<li><p>蜂鸣器（SP1）</p>
<p>​    蜂鸣器可提供提醒、报警等功能</p>
</li>
<li><p>继电器（K1）</p>
</li>
<li><p>输入输出接口（J3）</p>
</li>
<li><p>外接电源接口（J12）</p>
<p>​    可为竞赛平台之外的设备供电（该接口的供电能力较弱）</p>
</li>
<li><p>信号放大模块（U26及其周围器件）</p>
<p>​    J7放大模块外部接口</p>
</li>
<li><p>ADC转换芯片（U16）</p>
<p>​    竞赛平台的ADC转换芯片PCF8591</p>
</li>
<li><p>光敏器件（RD1）</p>
<p>​    改变光敏器件的光照条件，器件电阻值发生变化</p>
</li>
<li><p>模拟电压输入电位器（Rb2）</p>
<p>​    调整电位器，ADC芯片可得到变化的模拟电压</p>
</li>
<li><p>信号放大调节电位器（Rb4）</p>
</li>
<li><p>方波发生器电位器（Rb3）</p>
<h2 id="准备工作"><a href="#准备工作" class="headerlink" title="准备工作"></a>准备工作</h2></li>
</ol>
<ul>
<li><h3 id="延迟函数"><a href="#延迟函数" class="headerlink" title="延迟函数"></a>延迟函数</h3><div class="note info">
            <p>这个可以用 STC-ISP 生成</p>
          </div>
<p>代码如下</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">delay</span><span class="params">()</span>		<span class="comment">//@11.0592MHz</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">unsigned</span> <span class="keyword">char</span> i, j, k;</span><br><span class="line">	_nop_();<span class="comment">// 包含于intrins.h中</span></span><br><span class="line">	_nop_();<span class="comment">// 空操作 （相当于8051 NOP 指令） 函数延时一个机器周期的时间。</span></span><br><span class="line">	i = <span class="number">9</span>;</span><br><span class="line">	j = <span class="number">104</span>;</span><br><span class="line">	k = <span class="number">139</span>;</span><br><span class="line">	<span class="keyword">do</span></span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">do</span></span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">while</span> (--k);</span><br><span class="line">		&#125; <span class="keyword">while</span> (--j);</span><br><span class="line">	&#125; <span class="keyword">while</span> (--i);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



</li>
</ul>
<ul>
<li><h2 id="正式内容"><a href="#正式内容" class="headerlink" title="正式内容"></a>正式内容</h2></li>
<li><h3 id="LED"><a href="#LED" class="headerlink" title="LED"></a>LED</h3><p>操作8*LED模块</p>
<p>1、IO扩展模式</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"reg52.h"</span></span></span><br><span class="line"></span><br><span class="line">sbit LCD_E = P1^<span class="number">7</span>;</span><br><span class="line">sbit RELAY = P0^<span class="number">4</span>;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">main</span><span class="params">(<span class="keyword">void</span>)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	LCD_E = <span class="number">0</span>;</span><br><span class="line">	<span class="keyword">while</span>(<span class="number">1</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		P2 = ((P2&amp;<span class="number">0x1f</span>)|<span class="number">0x80</span>);<span class="comment">// 选通 8*LED 指示灯模块锁存器。 0x1f:00011111  0x80:10000000</span></span><br><span class="line">		P0 = <span class="number">0xff</span>;            <span class="comment">// P25=0 P26=0 P27=1</span></span><br><span class="line">		P2 &amp;= <span class="number">0x1f</span>;           <span class="comment">// 8*LED 指示灯模块锁存器锁存。74HC138 译码器选择 Y0 输出。</span></span><br><span class="line">		<span class="built_in">delay</span>();              <span class="comment">//这个鬼东西，哪里去了？？？</span></span><br><span class="line">		P2 = ((P2&amp;<span class="number">0x1f</span>)|<span class="number">0x80</span>);</span><br><span class="line">		P0 = <span class="number">0x00</span>;</span><br><span class="line">		P2 &amp;= <span class="number">0x1f</span>;</span><br><span class="line">		<span class="built_in">delay</span>();</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>2、MM扩展模式</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"reg52.h"</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"absacc.h"</span></span></span><br><span class="line">sbit LCD_E = P1^<span class="number">7</span>;</span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">main</span><span class="params">(<span class="keyword">void</span>)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	LCD_E = <span class="number">0</span>; <span class="comment">//将 LCD 模块禁能，防止 LCD 模块对总线状态的影响</span></span><br><span class="line">	<span class="keyword">while</span>(<span class="number">1</span>)</span><br><span class="line">	&#123;                         <span class="comment">// LED 指示灯模块的地址为 0x8000</span></span><br><span class="line">        XBYTE[<span class="number">0x8000</span>] = <span class="number">0x00</span>; <span class="comment">// LED 指示灯全部点亮</span></span><br><span class="line">        <span class="built_in">delay</span>();</span><br><span class="line">        </span><br><span class="line">        XBYTE[<span class="number">0x8000</span>] = <span class="number">0xff</span>; <span class="comment">// LED 指示灯全部熄灭</span></span><br><span class="line">        <span class="built_in">delay</span>();</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



</li>
</ul>
<ul>
<li><h3 id="按键"><a href="#按键" class="headerlink" title="按键"></a>按键</h3><ol>
<li><h4 id="独立按键"><a href="#独立按键" class="headerlink" title="独立按键"></a>独立按键</h4><p>这个没啥说的，就一个防抖操作</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">sbit key = P30;</span><br><span class="line"><span class="keyword">if</span>(key==<span class="number">0</span>)</span><br><span class="line">&#123;</span><br><span class="line">    delayms(<span class="number">20</span>);<span class="comment">// 防抖核心代码</span></span><br><span class="line">    <span class="keyword">if</span>(key==<span class="number">0</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">// 自定义代码区域</span></span><br><span class="line">        <span class="keyword">while</span>(!key);<span class="comment">// 防止按键跑飞，暂停程序，等待松开按键</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



</li>
</ol>
</li>
</ul>
<ol start="2">
<li><h4 id="矩阵按键"><a href="#矩阵按键" class="headerlink" title="矩阵按键"></a>矩阵按键</h4><p>​    我真的是头疼啊，重复，代码长，易出错……</p>
<p>​    按键的检测原理是这样的：</p>
<p>​            首先，先把非共极端的电压拉高，之后拉低共极端，如果按键按下，那么在非共极端就会检测到异常（值为0），此时就可以查找出哪个键被按下了</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"stc15f2k60s2.h"</span></span></span><br><span class="line"></span><br><span class="line">code <span class="keyword">unsigned</span> <span class="keyword">char</span> tab[] = &#123;<span class="number">0xc0</span>, <span class="number">0xf9</span>, <span class="number">0xa4</span>, <span class="number">0xb0</span>, <span class="number">0x99</span>, <span class="number">0x92</span>, <span class="number">0x82</span>, <span class="number">0xf8</span>, <span class="number">0x80</span>, <span class="number">0x90</span>&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">unsigned</span> <span class="keyword">char</span> num = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">unsigned</span> <span class="keyword">char</span> temp;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">delayms</span><span class="params">(<span class="keyword">unsigned</span> <span class="keyword">char</span> m)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">int</span> a, b;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span> (a = <span class="number">0</span>; a &lt; <span class="number">500</span>; a++)</span><br><span class="line">		<span class="keyword">for</span> (b = <span class="number">0</span>; b &lt; m; b++)</span><br><span class="line">			;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Key_Scan</span><span class="params">(<span class="keyword">void</span>)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">//判断S4 ~ S7</span></span><br><span class="line">	P3 = <span class="number">0xFF</span>;P44 = <span class="number">0</span>;P42 = <span class="number">1</span>; <span class="comment">// 配置要检测的按键</span></span><br><span class="line">	temp = P3 &amp; <span class="number">0x0F</span>;</span><br><span class="line">	<span class="keyword">if</span> (temp != <span class="number">0x0F</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		delayms(<span class="number">1</span>); <span class="comment">// 科学防抖</span></span><br><span class="line">		P3 = <span class="number">0xFF</span>;</span><br><span class="line">		temp = P3 &amp; <span class="number">0x0F</span>;</span><br><span class="line">		<span class="keyword">if</span> (temp != <span class="number">0x0F</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">switch</span> (temp)</span><br><span class="line">			&#123;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">0x0E</span>:num = <span class="number">7</span>;<span class="keyword">break</span>;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">0x0D</span>:num = <span class="number">6</span>;<span class="keyword">break</span>;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">0x0B</span>:num = <span class="number">5</span>;<span class="keyword">break</span>;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">0x07</span>:num = <span class="number">4</span>;<span class="keyword">break</span>;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">    <span class="comment">//判断S8 ~ S11</span></span><br><span class="line">	P3 = <span class="number">0xFF</span>;P44 = <span class="number">1</span>;P42 = <span class="number">0</span>; <span class="comment">// 配置要检测的按键</span></span><br><span class="line">	temp = P3 &amp; <span class="number">0x0F</span>;</span><br><span class="line">	<span class="keyword">if</span> (temp != <span class="number">0x0F</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		delayms(<span class="number">1</span>); <span class="comment">// 科学防抖</span></span><br><span class="line">		P3 = <span class="number">0xFF</span>;</span><br><span class="line">		temp = P3 &amp; <span class="number">0x0F</span>;</span><br><span class="line">		<span class="keyword">if</span> (temp != <span class="number">0x0F</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">switch</span> (temp)</span><br><span class="line">			&#123;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">0x0E</span>:num = <span class="number">11</span>;<span class="keyword">break</span>;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">0x0D</span>:num = <span class="number">10</span>;<span class="keyword">break</span>;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">0x0B</span>:num =  <span class="number">9</span>;<span class="keyword">break</span>;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">0x07</span>:num =  <span class="number">8</span>;<span class="keyword">break</span>;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">    <span class="comment">//判断S12 ~ S15</span></span><br><span class="line">	P3 = <span class="number">0xDF</span>;P44 = <span class="number">1</span>;P42 = <span class="number">1</span>; <span class="comment">// 配置要检测的按键</span></span><br><span class="line">	temp = P3 &amp; <span class="number">0x0F</span>;</span><br><span class="line">	<span class="keyword">if</span> (temp != <span class="number">0x0F</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		delayms(<span class="number">1</span>); <span class="comment">// 科学防抖</span></span><br><span class="line">		P3 = <span class="number">0xDF</span>;</span><br><span class="line">		temp = P3 &amp; <span class="number">0x0F</span>;</span><br><span class="line">		<span class="keyword">if</span> (temp != <span class="number">0x0F</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">switch</span> (temp)</span><br><span class="line">			&#123;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">0x0E</span>:num = <span class="number">15</span>;<span class="keyword">break</span>;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">0x0D</span>:num = <span class="number">14</span>;<span class="keyword">break</span>;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">0x0B</span>:num = <span class="number">13</span>;<span class="keyword">break</span>;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">0x07</span>:num = <span class="number">12</span>;<span class="keyword">break</span>;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">    <span class="comment">//判断S16 ~ S19</span></span><br><span class="line">	P3 = <span class="number">0xEF</span>;P44 = <span class="number">1</span>;P42 = <span class="number">1</span>; <span class="comment">// 配置要检测的按键</span></span><br><span class="line">	temp = P3 &amp; <span class="number">0x0F</span>;</span><br><span class="line">	<span class="keyword">if</span> (temp != <span class="number">0x0F</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		delayms(<span class="number">1</span>); <span class="comment">// 科学防抖</span></span><br><span class="line">		P3 = <span class="number">0xEF</span>;</span><br><span class="line">		temp = P3 &amp; <span class="number">0x0F</span>;</span><br><span class="line">		<span class="keyword">if</span> (temp != <span class="number">0x0F</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">switch</span> (temp)</span><br><span class="line">			&#123;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">0x0E</span>:num = <span class="number">19</span>;<span class="keyword">break</span>;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">0x0d</span>:num = <span class="number">18</span>;<span class="keyword">break</span>;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">0x0B</span>:num = <span class="number">17</span>;<span class="keyword">break</span>;</span><br><span class="line">			<span class="keyword">case</span> <span class="number">0x07</span>:num = <span class="number">16</span>;<span class="keyword">break</span>;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">display</span><span class="params">(<span class="keyword">unsigned</span> <span class="keyword">char</span> x)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">unsigned</span> <span class="keyword">char</span> ge, shi, bai;</span><br><span class="line">	bai = x / <span class="number">100</span>;</span><br><span class="line">	shi = (x / <span class="number">10</span>) % <span class="number">10</span>;</span><br><span class="line">	ge = x % <span class="number">10</span>;</span><br><span class="line"></span><br><span class="line">	P2 = <span class="number">0xC0</span>;</span><br><span class="line">	P0 = <span class="number">0x80</span>;</span><br><span class="line">	P2 = <span class="number">0xE0</span>;</span><br><span class="line">	P0 = tab[ge];</span><br><span class="line">	delayms(<span class="number">1</span>);</span><br><span class="line"></span><br><span class="line">	P2 = <span class="number">0xC0</span>;</span><br><span class="line">	P0 = <span class="number">0x40</span>;</span><br><span class="line">	P2 = <span class="number">0xE0</span>;</span><br><span class="line">	P0 = tab[shi];</span><br><span class="line">	delayms(<span class="number">1</span>);</span><br><span class="line"></span><br><span class="line">	P2 = <span class="number">0xC0</span>;</span><br><span class="line">	P0 = <span class="number">0x20</span>;</span><br><span class="line">	P2 = <span class="number">0xE0</span>;</span><br><span class="line">	P0 = tab[bai];</span><br><span class="line">	delayms(<span class="number">1</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">main</span><span class="params">(<span class="keyword">void</span>)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	P2 = <span class="number">0x80</span>;</span><br><span class="line">	P0 = <span class="number">0xFF</span>;</span><br><span class="line">	P2 = <span class="number">0xA0</span>;</span><br><span class="line">	P0 = <span class="number">0x00</span>;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">while</span> (<span class="number">1</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="built_in">display</span>(num);</span><br><span class="line">		Key_Scan();</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



</li>
</ol>
<ul>
<li><h3 id="数码管"><a href="#数码管" class="headerlink" title="数码管"></a>数码管</h3><p>数码管动态扫描显示</p>
<div class="note info">
            <p>数码管的刷新周期要小于24ms，否则就会出现闪动的情况，<br>特别指出，在24ms下，数码管已经出现暗淡，轻微闪烁的情况，<br>由于现在科学界对于人体眼球的刷新频率还没有一个确切的定论，现在只能确定一个范围</p>
          </div>
<p>1、MM扩展模式</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">  <span class="function"><span class="keyword">void</span> <span class="title">display</span><span class="params">(<span class="keyword">void</span>)</span></span></span><br><span class="line"><span class="function">  </span>&#123;</span><br><span class="line">  	XBYTE[<span class="number">0xE000</span>] = <span class="number">0xff</span>;<span class="comment">//数码管消隐</span></span><br><span class="line">  	XBYTE[<span class="number">0xC000</span>] = <span class="number">0xff</span>;<span class="comment">//数码管位选</span></span><br><span class="line">  	XBYTE[<span class="number">0xE000</span>] = tab[dspbuf[dspcom]];<span class="comment">//数码管段码输入</span></span><br><span class="line">      <span class="comment">//数码管段码端的操作地址为 0xE000，数码管位选端口的操作地址为 0xC000 </span></span><br><span class="line">  	<span class="keyword">if</span>（++dspcom == <span class="number">8</span>）&#123;</span><br><span class="line">  	dspcom = <span class="number">0</span>;</span><br><span class="line">  	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>2、IO扩展模式</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">  <span class="function"><span class="keyword">void</span> <span class="title">display</span><span class="params">(<span class="keyword">void</span>)</span></span></span><br><span class="line"><span class="function">  </span>&#123;</span><br><span class="line">  	P2 = ((P2&amp;<span class="number">0x1f</span>)|<span class="number">0xe0</span>); <span class="comment">//数码管消隐  e0:11100000</span></span><br><span class="line">  	P0 = <span class="number">0xff</span>;</span><br><span class="line">  	P2 &amp;= <span class="number">0x1f</span>;</span><br><span class="line">  </span><br><span class="line">  	P2 = ((P2&amp;<span class="number">0x1f</span>)|<span class="number">0xc0</span>); <span class="comment">//位选控制    c0:11000000</span></span><br><span class="line">  	P0 = <span class="number">1</span>&lt;&lt;dspcom;</span><br><span class="line">  	P2 &amp;= <span class="number">0x1f</span>;</span><br><span class="line">  </span><br><span class="line">  	P2 = ((P2&amp;<span class="number">0x1f</span>)|<span class="number">0xe0</span>); <span class="comment">//段码输入    e0:11100000</span></span><br><span class="line">  	P0 = tab[dspbuff[dspcom]];</span><br><span class="line">  	P2 &amp;= <span class="number">0x1f</span>;</span><br><span class="line">  </span><br><span class="line">  	<span class="keyword">if</span>（++dspcom == <span class="number">8</span>）&#123;</span><br><span class="line">  	dspcom = <span class="number">0</span>;</span><br><span class="line">  	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>这个数码管告诉我，睡觉有多么的重要</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"stc15f2k60s2.h"</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"intrins.h"</span></span></span><br><span class="line"></span><br><span class="line">code <span class="keyword">unsigned</span> <span class="keyword">char</span> tab[] = &#123;<span class="number">0xc0</span>, <span class="number">0xf9</span>, <span class="number">0xa4</span>, <span class="number">0xb0</span>, <span class="number">0x99</span>, <span class="number">0x92</span>, <span class="number">0x82</span>, <span class="number">0xf8</span>, <span class="number">0x80</span>, <span class="number">0x90</span>&#125;;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">delayms</span><span class="params">(<span class="keyword">unsigned</span> <span class="keyword">int</span> m)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="keyword">int</span> a, b;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">for</span> (a = <span class="number">0</span>; a &lt; <span class="number">500</span>; a++)</span><br><span class="line">    <span class="keyword">for</span> (b = <span class="number">0</span>; b &lt; m; b++)</span><br><span class="line">      ;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">char</span> x = <span class="number">1</span>;  <span class="comment">// 我也不知道为什么要写到这里来，什么鬼？？</span></span><br><span class="line"><span class="keyword">char</span> i;      <span class="comment">// 同上</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">main</span><span class="params">(<span class="keyword">void</span>)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	P2 = <span class="number">0xA0</span>;</span><br><span class="line">	P0 = <span class="number">0x00</span>;</span><br><span class="line">	P2 = <span class="number">0x80</span>;</span><br><span class="line">	P0 = <span class="number">0xff</span>;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">while</span> (<span class="number">1</span>)</span><br><span class="line">	&#123;</span><br><span class="line">		x=<span class="number">1</span>;</span><br><span class="line">		<span class="keyword">for</span> (i=<span class="number">0</span>;i&lt;<span class="number">8</span>;i++)</span><br><span class="line">		&#123;</span><br><span class="line">			P2=<span class="number">0xC0</span>;</span><br><span class="line">			P0= x;  <span class="comment">// 位选</span></span><br><span class="line">			x=x*<span class="number">2</span>;  <span class="comment">// 或者 x&lt;&lt;i</span></span><br><span class="line">			P2=<span class="number">0xE0</span>;</span><br><span class="line">			P0= tab[i]; <span class="comment">//段选</span></span><br><span class="line">			delayms(<span class="number">1</span>);</span><br><span class="line"></span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><h3 id="蜂鸣器"><a href="#蜂鸣器" class="headerlink" title="蜂鸣器"></a>蜂鸣器</h3><p>其实就这两行代码</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">P2 = <span class="number">0xA0</span>;</span><br><span class="line">P0 = 代码编号; <span class="comment">//这里也可以用0x00 与0xFF ，但是我感觉不怎么好</span></span><br></pre></td></tr></table></figure>

<table>
<thead>
<tr>
<th>代码编号</th>
<th>功能</th>
</tr>
</thead>
<tbody><tr>
<td>0x10</td>
<td>点亮L10 ， 打开继电器</td>
</tr>
<tr>
<td>0x40</td>
<td>蜂鸣器响</td>
</tr>
<tr>
<td>0x50</td>
<td>蜂鸣器响，点亮L10 ， 打开继电器</td>
</tr>
</tbody></table>
</li>
</ul>
<ul>
<li><h3 id="光敏器件"><a href="#光敏器件" class="headerlink" title="光敏器件"></a>光敏器件</h3></li>
<li><h3 id="霍尔元件"><a href="#霍尔元件" class="headerlink" title="霍尔元件"></a>霍尔元件</h3></li>
<li><h3 id="超声波测距模块"><a href="#超声波测距模块" class="headerlink" title="超声波测距模块"></a>超声波测距模块</h3></li>
<li><h3 id="红外收发模块"><a href="#红外收发模块" class="headerlink" title="红外收发模块"></a>红外收发模块</h3></li>
<li><h3 id="温度传感器"><a href="#温度传感器" class="headerlink" title="温度传感器"></a>温度传感器</h3><p>温度传感器有且仅有一个引脚与其相连，引脚为P14</p>
</li>
</ul>
<ul>
<li><p>3</p>
</li>
<li><p>3</p>
</li>
<li><p>3</p>
</li>
<li><p>3</p>
</li>
<li><p>3</p>
</li>
<li><p>3</p>
</li>
<li><p>3</p>
</li>
</ul>

    </div>

    
    
    
        <div class="reward-container">
  <div></div>
  <button disable="enable" onclick="var qr = document.getElementById(&quot;qr&quot;); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/images/wechatpay.png" alt="YChienHung 微信支付">
        <p>微信支付</p>
      </div>
      
      <div style="display: inline-block;">
        <img src="/images/alipay.jpg" alt="YChienHung 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>

        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>YChienHung
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://ychienhung.gitee.io/2019/12/27/%E5%8D%95%E7%89%87%E6%9C%BA%E5%9F%B9%E8%AE%AD%E6%97%A5%E5%BF%97/" title="单片机培训日志">https://ychienhung.gitee.io/2019/12/27/单片机培训日志/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" rel="noopener" target="_blank"><i class="fa fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/%E5%8D%95%E7%89%87%E6%9C%BA/" rel="tag"><i class="fa fa-tag"></i> 单片机</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2019/12/27/Visual-Studio-%E4%BF%AE%E7%82%BC%E6%89%8B%E5%86%8C/" rel="prev" title="Visual Studio 修炼手册">
      <i class="fa fa-chevron-left"></i> Visual Studio 修炼手册
    </a></div>
      <div class="post-nav-item">
    <a href="/2019/12/28/C%E8%AF%AD%E8%A8%80%E4%BB%A3%E7%A0%81%E8%A7%84%E8%8C%83%EF%BC%88%E7%BC%96%E7%A8%8B%E8%A7%84%E8%8C%83%EF%BC%89/" rel="next" title="C语言代码规范（编程规范）">
      C语言代码规范（编程规范） <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          
    
  <div class="comments">
    <div id="lv-container" data-id="city" data-uid="MTAyMC8zOTIxMi8xNTczOQ=="></div>
  </div>
  

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#开发板介绍"><span class="nav-number">1.</span> <span class="nav-text">开发板介绍</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#准备工作"><span class="nav-number">2.</span> <span class="nav-text">准备工作</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#延迟函数"><span class="nav-number">2.1.</span> <span class="nav-text">延迟函数</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#正式内容"><span class="nav-number">3.</span> <span class="nav-text">正式内容</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#LED"><span class="nav-number">3.1.</span> <span class="nav-text">LED</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#按键"><span class="nav-number">3.2.</span> <span class="nav-text">按键</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#独立按键"><span class="nav-number">3.2.1.</span> <span class="nav-text">独立按键</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#矩阵按键"><span class="nav-number">3.2.2.</span> <span class="nav-text">矩阵按键</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#数码管"><span class="nav-number">3.3.</span> <span class="nav-text">数码管</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#蜂鸣器"><span class="nav-number">3.4.</span> <span class="nav-text">蜂鸣器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#光敏器件"><span class="nav-number">3.5.</span> <span class="nav-text">光敏器件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#霍尔元件"><span class="nav-number">3.6.</span> <span class="nav-text">霍尔元件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#超声波测距模块"><span class="nav-number">3.7.</span> <span class="nav-text">超声波测距模块</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#红外收发模块"><span class="nav-number">3.8.</span> <span class="nav-text">红外收发模块</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#温度传感器"><span class="nav-number">3.9.</span> <span class="nav-text">温度传感器</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="YChienHung"
      src="/images/avatar.png">
  <p class="site-author-name" itemprop="name">YChienHung</p>
  <div class="site-description" itemprop="description">Forget me not.</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">18</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">15</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/ychienhung" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;ychienhung" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://gitee.com/ychienhung" title="Gitee → https:&#x2F;&#x2F;gitee.com&#x2F;ychienhung" rel="noopener" target="_blank"><i class="fa fa-fw fa-gitee"></i>Gitee</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/u/6664907998" title="Weibo → https:&#x2F;&#x2F;weibo.com&#x2F;u&#x2F;6664907998" rel="noopener" target="_blank"><i class="fa fa-fw fa-weibo"></i>Weibo</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:1399449399@qq.com" title="E-Mail → mailto:1399449399@qq.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="/atom.xml" title="RSS → &#x2F;atom.xml"><i class="fa fa-fw fa-rss"></i>RSS</a>
      </span>
  </div>
  <div class="cc-license motion-element" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="https://diygod.me/" title="https:&#x2F;&#x2F;diygod.me" rel="noopener" target="_blank">DIYGod</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 2019 – 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">YChienHung</span>
</div>

<!-- 在网页底部添加网站运行时间 -->
<span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span>
<script>
    var now = new Date();
    function createtime() {
        var grt= new Date("07/20/2019 19:21:37");//此处修改你的建站时间或者网站上线时间
        now.setTime(now.getTime()+250);
        days = (now - grt ) / 1000 / 60 / 60 / 24; dnum = Math.floor(days);
        hours = (now - grt ) / 1000 / 60 / 60 - (24 * dnum); hnum = Math.floor(hours);
        if(String(hnum).length ==1 ){hnum = "0" + hnum;} minutes = (now - grt ) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum);
        mnum = Math.floor(minutes); if(String(mnum).length ==1 ){mnum = "0" + mnum;}
        seconds = (now - grt ) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
        snum = Math.round(seconds); if(String(snum).length ==1 ){snum = "0" + snum;}
        document.getElementById("timeDate").innerHTML = "本站已经运行 "+dnum+" 天 ";
        document.getElementById("times").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒";
    }
setInterval("createtime()",250);
</script>
<br>

托管于<a href="https://gitee.com/" target="_blank" rel="nofollow"> Gitee</a>


  <span class="post-meta-divider">|</span>

  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v4.2.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> v7.6.0
  </div>

<!-- 新增访客统计代码-->
<div class="busuanzi-count">
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
  <span id="busuanzi_container_site_pv">本站已被访问 <span id="busuanzi_value_site_pv"></span>次</span>
</div>
<!-- 新增访客统计代码 END-->

<!-- 页面点击小红心 -->
<script type="text/javascript" src="\js\love.js"></script>
<!--浏览器搞笑标题-->
<!--<script type="text/javascript" src="\js\FunnyTitle.js"></script>-->

<!-- require APlayer -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css">
<script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script>
<!-- require MetingJS -->
<script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script>

<!--MusicPlayer-->
<meting-js
  fixed ="true"
	server="tencent"
	type  ="playlist"
	id    ="3578030853"
  loop	="all"
  order	="list"
  listFolded="false">
</meting-js>
        








      </div>
    </footer>
  </div>

  
  <script size="150" alpha="0.6" zIndex="-2" src="//cdn.jsdelivr.net/gh/theme-next/theme-next-canvas-ribbon@1/canvas-ribbon.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  

<script>
NexT.utils.loadComments(document.querySelector('#lv-container'), () => {
  window.livereOptions = {
    refer: location.pathname.replace(CONFIG.root, '').replace('index.html', '')
  };
  (function(d, s) {
    var j, e = d.getElementsByTagName(s)[0];
    if (typeof LivereTower === 'function') { return; }
    j = d.createElement(s);
    j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
    j.async = true;
    e.parentNode.insertBefore(j, e);
  })(document, 'script');
});
</script>

</body>
</html>
